package cjgl.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class CounterDAO {
   public Integer getValue() {
	   
	   Integer count=null;
	   String sql="select * from counter";
	   
	   Connection conn=ConnectionFactory.getConnection();
	   if(conn!=null) {
		 Statement stmt;
		try {
			stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
		    if(rs.next()) {
			 count=rs.getInt(1);
		   }
		   conn.close();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		  
	   }
	   return count;
   }

   
   public void setValue(int value) {
	   String sql="update counter set count "+value;
	   Connection conn=ConnectionFactory.getConnection(); 
	   Statement stmt;
	try {
		stmt = conn.createStatement();
		stmt.execute(sql);
	    conn.close();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	  
   }
   
   
   
}
